 def prost(x):
    fl = True
    for i in range(2, x):
        if x % i == 0:
            fl = False
            break
    return fl
s = input()
m = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
if s.count(' ') >1:
    a, b, c = s.split()
    if a in m and b in m and c in m and a !='zero':
        summ = m.index(a)*100 + m.index(b)*10 + m.index(c)
        if prost(summ):
            print(summ)
        else:
            x = y = 0
            for i in range(summ+1, 998):
                if prost(i):
                    x = i
                    break
            for j in range(summ, 2, -1):
                if prost(j):
                    y = j
                    break
            if (x - summ) <= (summ - y):
                print(x)
            else:
                print(y)
    else:
        print('Wrong input')
else:
    print('Wrong input')
